#!/usr/bin/env python

from .models import UserProfile,TempGroup,Template,FieldType,TempField,Instance,ProFLow,FlowTask,FlowInst,\
SubTask,SubTaskAttach,ProEvent,EventAttach
from rest_framework import serializers

class UserSeri(serializers.HyperlinkedModelSerializer):
    
    def create(self, validated_data):
        UserProfile = super(UserSeri, self).create(validated_data=validated_data)
        UserProfile.set_password(validated_data["password"])
        UserProfile.save()
        return UserProfile
    
    class Meta:
        model = UserProfile
        #fields = ['id','url', 'username', 'email', 'groups']
        fields = '__all__'
        

class TempGroupSeri(serializers.ModelSerializer):
    class Meta:
        model = TempGroup
        fields = '__all__'
        
class TemplateWriteSeri(serializers.ModelSerializer):
    class Meta:
        model = Template
        fields = '__all__'
        
class TemplateReadSeri(serializers.ModelSerializer):
    class Meta:
        model = Template
        fields = '__all__'
        depth = 2

class FieldTypeSeri(serializers.ModelSerializer):
    class Meta:
        model = FieldType
        fields = '__all__'

class TempFieldSeri(serializers.ModelSerializer):
    type_name = serializers.ReadOnlyField()
    class Meta:
        model = TempField
        fields = '__all__'

class InstanceSeri(serializers.ModelSerializer):
    class Meta:
        model = Instance
        fields = '__all__'
    
class ProFlowSeri(serializers.ModelSerializer):
    class Meta:
        model = ProFLow
        fields = '__all__'

class FlowTaskSeri(serializers.ModelSerializer):
    class Meta:
        model = FlowTask
        fields = '__all__'

class FlowInstSeri(serializers.ModelSerializer):
    ch_name = serializers.ReadOnlyField()
    class Meta:
        model = FlowInst
        fields = '__all__'

class SubTaskSeri(serializers.ModelSerializer):
    task_name = serializers.ReadOnlyField()
    flow_name = serializers.ReadOnlyField()
    class Meta:
        model = SubTask
        fields = '__all__'

class SubTaskAttachSeri(serializers.ModelSerializer):
    subtask_title = serializers.ReadOnlyField()
    class Meta:
        model = SubTaskAttach
        fields = '__all__'
        
class ProEventSeri(serializers.ModelSerializer):
    class Meta:
        model = ProEvent
        fields = '__all__'
    
class EventAttachSeri(serializers.ModelSerializer):
    class Meta:
        model = EventAttach
        fields = '__all__'
